package students_files_test01;

import java.util.ArrayList;
import java.util.Iterator;

public class Order implements Iterable<OrderItem>{

    private ArrayList<OrderItem> items;

    public Order(){
        items = new ArrayList<>();
    }

    @Override
    public Iterator<OrderItem> iterator() {
        return items.iterator();
    }

    public void addItem(OrderItem orderItem){
        items.add(orderItem);
    }

    public void removeItem(OrderItem orderItem){
        items.remove(orderItem);
    }

    public OrderItem getItem(Product product){
        for (OrderItem orderItem : items){
            if (orderItem.getProduct().equals(product)){
                return orderItem;
            }
        }
        return null;
    }

    public int getNumberOfItems(){
        return items.size();
    }

    public double getTotalCost(){
        double TC = 0;
        for (OrderItem orderItem : items){
            TC += orderItem.getValue();
        }
        return TC;
    }
}
